/******************************************************************************

	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2008, 2009, 2010.

	This file is part of Maxsi Engine.

	Maxsi Engine is free software: you can redistribute it and/or modify it
	under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or (at your
	option) any later version.

	Maxsi engine is distributed in the hope that it will be useful, but WITHOUT
	ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
	FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
	for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with Maxsi Engine. If not, see <http://www.gnu.org/licenses/>.

	MaxsiEngine.dll
	A general purpose C++ library for the Maxsi Technology Project.

	MaxsiList.h
	A system for handling BYTE** based lists.

******************************************************************************/

#ifndef MaxsiList_H
#define MaxsiList_H

BeginMaxsiNamespace

//=============================================================================
//	String redirection macros
//=============================================================================
#ifdef Maxsi_Using_Unicode_Internally

	#define StringListToBuffer StringListToBufferW
	#define BuildStringList BuildStringListW
	#define GetListEntryM GetListEntryW
	#define SetListEntryM SetListEntryW
	#define AddListEntryM AddListEntryW

#else

	#define StringListToBuffer StringListToBufferA
	#define BuildStringList BuildStringListA
	#define GetListEntryM GetListEntryA
	#define SetListEntryM SetListEntryA
	#define AddListEntryM AddListEntryA

#endif

//=============================================================================
//	Type declarations
//==================================== =========================================
typedef BYTE**	List;
typedef BYTE*	ListC; // Interestingly, ListC means List Content but it's not actually the content.

//=============================================================================
// Functions that convert a List of buffers to a continuous buffer  
//=============================================================================
LINK	BYTE*			BufferListToBuffer(List BufferList); // No null-termination
LINK	BYTE*			BufferListToBufferN(List BufferList); // Null-terminated!
LINK	char*			StringListToBufferA(List StringList);
LINK	wchar_t*		StringListToBufferW(List StringList);

//=============================================================================
// Functions that convert an amount of buffers into a List
//=============================================================================
LINK	List			BuildStringListA(size_t NumParameters, ...);
LINK	List			BuildStringListW(size_t NumParameters, ...);
LINK	List			BuildBufferList(size_t NumParameters, ...);

//=============================================================================
//	List Related Functions
//=============================================================================
LINK	List			CreateList		(size_t Size);
LINK	ListC			CreateListC		(size_t Size);
LINK	bool			SetListSize		(List list, size_t NewSize);
LINK	bool			DeleteList		(List list);

LINK	bool			AddListEntry	(List* list, BYTE* Buffer, size_t BufferSize);
LINK	bool			AddListEntryA	(List* list, char* String);
LINK	bool			AddListEntryW	(List* list, wchar_t* String);
LINK	BYTE*			GetListEntry	(List list, size_t Number);
LINK	char*			GetListEntryA	(List list, size_t Number);
LINK	wchar_t*		GetListEntryW	(List list, size_t Number);
LINK	bool			SetListEntry	(List list, size_t Number, BYTE* Buffer, size_t BufferSize);
LINK	bool			SetListEntryA	(List list, size_t Number, char* String);
LINK	bool			SetListEntryW	(List list, size_t Number, wchar_t* String);
LINK	size_t			GetListSize		(List list);
LINK	size_t			GetListEntrySize(List list, size_t Number);
LINK	List			DuplicateList	(List list);

EndMaxsiNamespace

#endif
